const weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];

const formatterDateTime = function(date, type) {
  if (date == null) {
    date = new Date()
  }
  const month = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  const hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
  const minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  const second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
  switch (type) {
    case 0:
      return date.getFullYear() + '年' + month + '月' + day + '日' + hour + '时' + minute + '分' + second + '秒';
    default:
      return date.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  }
}

const formatterDate = function(date, type) {
  if (date == null) {
    date = new Date()
  }
  const month = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  switch (type) {
    case 0:
      return date.getFullYear() + '年' + month + '月' + day + '日';
    default:
      return date.getFullYear() + '-' + month + '-' + day;
  }
}

const formatterTime = function(date, type) {
  if (date == null) {
    date = new Date()
  }
  const hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
  const minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  const second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
  const month = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  switch (type) {
    case 0:
      return hour + '时' + minute + '分' + second + '秒';
    default:
      return hour + ':' + minute + ':' + second;
  }
}

const formatterMonth = function(date, type) {
  if (date == null) {
    date = new Date()
  }
  const month = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  switch (type) {
    case 0:
      return date.getFullYear() + '年' + month + '月';
    default:
      return date.getFullYear() + '-' + month;
  }
}

const formatterWeekDay = function(date, type) {
  if (date == null) {
    date = new Date()
  }
  return weeks[date.getDay()]
}
export {
  formatterDateTime,
  formatterDate,
  formatterTime,
  formatterMonth,
  formatterWeekDay
}
